<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (head, val) {
    //如果在链表头部删除其头部那么直接head.nextz
    if (head.val === val) return head.next;
    let pre = head;
    let cur = head.next;
    while (cur !== null && cur.val !== val) {
      pre = cur;
      cur = cur.next;
    }
    if (cur.val === val) pre.next = cur.next;
    return head;
  };
  console.log(arr(head = [4, 5, 1, 9], val = 5));
</script>

</html>